$(function () {
    init();
    function init() {
        mui('.mui-scroll-wrapper').scroll({
            deceleration: 0.0005 //flick 减速系数，系数越大，滚动速度越慢，滚动距离越小，默认值0.0006
        });
        queryTopCategory(function (res) {
            var id = res.rows[0].id;
            querySecondCategory(id);
        });

        $(".lt_menu_ul").on("tap","li",function (e) {
            var id = $(this).data("id");
            querySecondCategory(id);
        })
    }

    function queryTopCategory(callback) {
        $.get("/category/queryTopCategory", function (res) {
            console.log(res);
            var rows = res.rows;
            var htmlArr = [];
            for (var i = 0; i < rows.length; i++) {
                htmlArr.push('<li data-id=' + rows[i].id + '><a href="#">' + rows[i].categoryName + '</a></li>');
            }
            var htmlStr = htmlArr.join("");
            $(".lt_menu_ul").html(htmlStr);
            callback && callback(res);
        })
    }

    function querySecondCategory(id) {
        $.get("/category/querySecondCategory?id=" + id, function (res) {
            var rows = res.rows;
            var htmlArr = [];
            for (var i = 0; i < rows.length; i++) {
                htmlArr.push('<a href="javascript:;"> <img src="' + rows[i].brandLogo + '" alt=""> <p>' + rows[i].brandName + '</p> </a>');
            }
            // 获取要渲染的html代码
            var htmlStr = htmlArr.join("");
            $(".lt_item").html(htmlStr);
        })
    }
})